package com.fc.remoting;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

public abstract class AbstractRemotingServer implements IRemotingServer{
	private static final int DEFAULT_BACKLOG = 1024;
	private static final int DEFAULT_RCVBUF = 32*1024;
	private static final int DEFAULT_SNDBUF = 32*1024;
	
	@Override
	public ServerBootstrap getDefaultServerBootstrap(EventLoopGroup bossGroup,EventLoopGroup workerGroup) {
		ServerBootstrap serverBootstrap = new ServerBootstrap();
		serverBootstrap.group(bossGroup, workerGroup)
				.option(ChannelOption.SO_BACKLOG, DEFAULT_BACKLOG)
				.option(ChannelOption.SO_REUSEADDR, true)
				.option(ChannelOption.TCP_NODELAY, true)
				.childOption(ChannelOption.SO_KEEPALIVE, false)
				.channel(NioServerSocketChannel.class)
				.handler(new LoggingHandler(LogLevel.DEBUG))
				.childOption(ChannelOption.SO_RCVBUF,DEFAULT_RCVBUF)
				.childOption(ChannelOption.SO_SNDBUF,DEFAULT_SNDBUF);
				
		return serverBootstrap;
	}
}
